/**
  ******************************************************************************
  * @file    py32f420_hal_gpio_ex.h
  * @author  MCU Application Team
  * @brief   Header file of GPIO HAL Extended module.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by Puya under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __PY32F420_HAL_GPIO_EX_H
#define __PY32F420_HAL_GPIO_EX_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "py32f420_hal_def.h"

/** @addtogroup PY32F420_HAL_Driver
  * @{
  */

/** @defgroup GPIOEx GPIOEx
  * @brief GPIO Extended HAL module driver
  * @{
  */

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup GPIOEx_Exported_Constants GPIOEx Exported Constants
  * @{
  */

/** @defgroup GPIOEx_Alternate_function_selection GPIOEx Alternate function selection
  * @{
  */

/*------------------------- PY32F420 ------------------------*/
/**
  * @brief   AF 0 selection
  */
#define GPIO_AF0_MCO1          ((uint8_t)0x00)  /*!< MCO1 Alternate Function mapping */
#define GPIO_AF0_MCO2          ((uint8_t)0x00)  /*!< MCO2 Alternate Function mapping */
#define GPIO_AF0_SWJ           ((uint8_t)0x00)  /*!< SWJ (SWD/JTAG) Alternate Function mapping */
#define GPIO_AF0_TRACE         ((uint8_t)0x00)  /*!< TRACE Alternate Function mapping */
#define GPIO_AF0_TIM3          ((uint8_t)0x00)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF0_TIM8          ((uint8_t)0x00)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF0_ADC           ((uint8_t)0x00)  /*!< ADC Alternate Function mapping */
#define GPIO_AF0_I2C1          ((uint8_t)0x00)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF0_I2C2          ((uint8_t)0x00)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF0_SPI1          ((uint8_t)0x00)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF0_SPI2          ((uint8_t)0x00)  /*!< SPI2 Alternate Function mapping */

/**
* @brief   AF 1 selection
*/
#define GPIO_AF1_TIM1          ((uint8_t)0x01)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF1_TIM2          ((uint8_t)0x01)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF1_TIM3          ((uint8_t)0x01)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF1_TIM8          ((uint8_t)0x01)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF1_SPI1          ((uint8_t)0x01)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF1_SPI2          ((uint8_t)0x01)  /*!< SPI2 Alternate Function mapping */
#define GPIO_AF1_USART1        ((uint8_t)0x01)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF1_UART1         ((uint8_t)0x01)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF1_COMP1         ((uint8_t)0x01)  /*!< COMP1 Alternate Function mapping */
#define GPIO_AF1_COMP2         ((uint8_t)0x01)  /*!< COMP2 Alternate Function mapping */
#define GPIO_AF1_COMP3         ((uint8_t)0x01)  /*!< COMP3 Alternate Function mapping */
#define GPIO_AF1_I2C1          ((uint8_t)0x01)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF1_I2C2          ((uint8_t)0x01)  /*!< I2C2 Alternate Function mapping */

/**
* @brief   AF 2 selection
*/
#define GPIO_AF2_TIM1          ((uint8_t)0x02)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF2_TIM2          ((uint8_t)0x02)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF2_TIM3          ((uint8_t)0x02)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF2_TIM8          ((uint8_t)0x02)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF2_COMP1         ((uint8_t)0x02)  /*!< COMP1 Alternate Function mapping */
#define GPIO_AF2_COMP2         ((uint8_t)0x02)  /*!< COMP2 Alternate Function mapping */
#define GPIO_AF2_I2C1          ((uint8_t)0x02)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF2_I2C2          ((uint8_t)0x02)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF2_SPI1          ((uint8_t)0x02)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF2_USART1        ((uint8_t)0x02)  /*!< USART1 Alternate Function mapping */

/**
* @brief   AF 3 selection
*/
#define GPIO_AF3_TIM1          ((uint8_t)0x03)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF3_TIM2          ((uint8_t)0x03)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF3_TIM3          ((uint8_t)0x03)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF3_I2C2          ((uint8_t)0x03)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF3_COMP1         ((uint8_t)0x03)  /*!< COMP1 Alternate Function mapping */
#define GPIO_AF3_COMP2         ((uint8_t)0x03)  /*!< COMP2 Alternate Function mapping */
#define GPIO_AF3_SPI1          ((uint8_t)0x03)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF3_SPI2          ((uint8_t)0x03)  /*!< SPI2 Alternate Function mapping */
#define GPIO_AF3_USART1        ((uint8_t)0x03)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF3_UART1         ((uint8_t)0x03)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF3_UART2         ((uint8_t)0x03)  /*!< UART2 Alternate Function mapping */

/**
* @brief   AF 4 selection
*/
#define GPIO_AF4_TIM1          ((uint8_t)0x04)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF4_TIM2          ((uint8_t)0x04)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF4_TIM3          ((uint8_t)0x04)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF4_TIM8          ((uint8_t)0x04)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF4_I2C1          ((uint8_t)0x04)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF4_I2C2          ((uint8_t)0x04)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF4_SPI1          ((uint8_t)0x04)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF4_UART2         ((uint8_t)0x04)  /*!< UART2 Alternate Function mapping */
#define GPIO_AF4_COMP1         ((uint8_t)0x04)  /*!< COMP1 Alternate Function mapping */

/**
* @brief   AF 5 selection
*/
#define GPIO_AF5_TIM1          ((uint8_t)0x05)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF5_TIM2          ((uint8_t)0x05)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF5_TIM3          ((uint8_t)0x05)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF5_TIM8          ((uint8_t)0x05)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF5_COMP1         ((uint8_t)0x05)  /*!< COMP1 Alternate Function mapping */
#define GPIO_AF5_COMP2         ((uint8_t)0x05)  /*!< COMP2 Alternate Function mapping */
#define GPIO_AF5_I2C1          ((uint8_t)0x05)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF5_SPI1          ((uint8_t)0x05)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF5_I2C2          ((uint8_t)0x05)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF5_UART1         ((uint8_t)0x05)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF5_USART1        ((uint8_t)0x05)  /*!< USART1 Alternate Function mapping */

/**
* @brief   AF 6 selection
*/
#define GPIO_AF6_TIM1          ((uint8_t)0x06)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF6_TIM2          ((uint8_t)0x06)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF6_TIM3          ((uint8_t)0x06)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF6_TIM8          ((uint8_t)0x06)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF6_I2C1          ((uint8_t)0x06)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF6_I2C2          ((uint8_t)0x06)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF6_SPI1          ((uint8_t)0x06)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF6_SPI2          ((uint8_t)0x06)  /*!< SPI2 Alternate Function mapping */
#define GPIO_AF6_USART1        ((uint8_t)0x06)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF6_LPTIM1        ((uint8_t)0x06)  /*!< LPTIM1 Alternate Function mapping */
#define GPIO_AF6_LPUART1       ((uint8_t)0x06)  /*!< LPUART1 Alternate Function mapping */
#define GPIO_AF6_FDCAN         ((uint8_t)0x06)  /*!< FDCAN Alternate Function mapping */
#define GPIO_AF6_COMP3         ((uint8_t)0x06)  /*!< FDCAN Alternate Function mapping */

/**
  * @brief   AF 7 selection
  */
#define GPIO_AF7_TIM1          ((uint8_t)0x07)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF7_TIM3          ((uint8_t)0x07)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF7_TIM8          ((uint8_t)0x07)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF7_I2C1          ((uint8_t)0x07)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF7_LPTIM1        ((uint8_t)0x07)  /*!< LPTIM1 Alternate Function mapping */
#define GPIO_AF7_USART1        ((uint8_t)0x07)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF7_COMP1         ((uint8_t)0x07)  /*!< COMP1 Alternate Function mapping */
#define GPIO_AF7_COMP2         ((uint8_t)0x07)  /*!< COMP2 Alternate Function mapping */
#define GPIO_AF7_COMP3         ((uint8_t)0x07)  /*!< COMP3 Alternate Function mapping */
#define GPIO_AF7_COMP4         ((uint8_t)0x07)  /*!< COMP4 Alternate Function mapping */
#define GPIO_AF7_FDCAN         ((uint8_t)0x07)  /*!< FDCAN Alternate Function mapping */
#define GPIO_AF7_SPI1          ((uint8_t)0x07)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF7_SPI2          ((uint8_t)0x07)  /*!< SPI2 Alternate Function mapping */

/**
  * @brief   AF 8 selection
  */
#define GPIO_AF8_TIM1          ((uint8_t)0x08U)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF8_TIM3          ((uint8_t)0x08U)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF8_TIM8          ((uint8_t)0x08U)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF8_LPTIM1        ((uint8_t)0x08U)  /*!< LPTIM1 Alternate Function mapping */
#define GPIO_AF8_LPUART1       ((uint8_t)0x08U)  /*!< LPUART1 Alternate Function mapping */
#define GPIO_AF8_I2C1          ((uint8_t)0x08U)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF8_I2C2          ((uint8_t)0x08U)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF8_SPI1          ((uint8_t)0x08U)  /*!< SPI1 Alternate Function mapping */
#define GPIO_AF8_USART1        ((uint8_t)0x08U)  /*!< USART1 Alternate Function mapping */

/**
  * @brief   AF 9 selection
  */
#define GPIO_AF9_TIM2          ((uint8_t)0x09U)  /*!< TIM2 Alternate Function mapping */
#define GPIO_AF9_TIM8          ((uint8_t)0x09U)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF9_USART1        ((uint8_t)0x09U)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF9_FDCAN         ((uint8_t)0x09U)  /*!< FDCAN Alternate Function mapping */
#define GPIO_AF9_I2C1          ((uint8_t)0x09U)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF9_I2C2          ((uint8_t)0x09U)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF9_LPTIM1        ((uint8_t)0x09U)  /*!< LPTIM1 Alternate Function mapping */

/**
  * @brief   AF 10 selection
  */
#define GPIO_AF10_EPWM         ((uint8_t)0x0A)   /*!< EPWM Alternate Function mapping */

/**
  * @brief   AF 11 selection
  */
#define GPIO_AF11_I2C1         ((uint8_t)0x0B)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF11_I2C2         ((uint8_t)0x0B)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF11_LPUART1      ((uint8_t)0x0B)  /*!< LPUART1 Alternate Function mapping */
#define GPIO_AF11_UART1        ((uint8_t)0x0B)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF11_UART2        ((uint8_t)0x0B)  /*!< UART2 Alternate Function mapping */
#define GPIO_AF11_USART1       ((uint8_t)0x0B)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF11_EPWM         ((uint8_t)0x0B)  /*!< EPWM Alternate Function mapping */
#define GPIO_AF11_EPWM1        ((uint8_t)0x0B)  /*!< EPWM1 Alternate Function mapping */
#define GPIO_AF11_EPWM2        ((uint8_t)0x0B)  /*!< EPWM2 Alternate Function mapping */
#define GPIO_AF11_EPWM3        ((uint8_t)0x0B)  /*!< EPWM3 Alternate Function mapping */
#define GPIO_AF11_EPWM4        ((uint8_t)0x0B)  /*!< EPWM4 Alternate Function mapping */
#define GPIO_AF11_EPWM5        ((uint8_t)0x0B)  /*!< EPWM5 Alternate Function mapping */
#define GPIO_AF11_EPWM6        ((uint8_t)0x0B)  /*!< EPWM6 Alternate Function mapping */

/**
  * @brief   AF 12 selection
  */
#define GPIO_AF12_TIM1         ((uint8_t)0x0C)  /*!< TIM1 Alternate Function mapping */
#define GPIO_AF12_USART1       ((uint8_t)0x0C)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF12_UART1        ((uint8_t)0x0C)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF12_UART2        ((uint8_t)0x0C)  /*!< UART2 Alternate Function mapping */
#define GPIO_AF12_I2C1         ((uint8_t)0x0C)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF12_I2C2         ((uint8_t)0x0C)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF12_LPUART1      ((uint8_t)0x0C)  /*!< LPUART1 Alternate Function mapping */
#define GPIO_AF12_LPTIM1       ((uint8_t)0x0C)  /*!< LPTIM1 Alternate Function mapping */
#define GPIO_AF12_FDCAN        ((uint8_t)0x0C)  /*!< FDCAN Alternate Function mapping */
#define GPIO_AF12_EPWM         ((uint8_t)0x0C)  /*!< EPWM Alternate Function mapping */

/**
  * @brief   AF 13 selection
  */
#define GPIO_AF13_UART1        ((uint8_t)0x0D)  /*!< UART1 Alternate Function mapping */
#define GPIO_AF13_UART2        ((uint8_t)0x0D)  /*!< UART2 Alternate Function mapping */
#define GPIO_AF13_USART1       ((uint8_t)0x0D)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF13_I2C1         ((uint8_t)0x0D)  /*!< I2C1 Alternate Function mapping */
#define GPIO_AF13_I2C2         ((uint8_t)0x0D)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF13_TIM8         ((uint8_t)0x0D)  /*!< TIM8 Alternate Function mapping */

/**
  * @brief   AF 14 selection
  */
#define GPIO_AF14_LPUART1      ((uint8_t)0x0E)  /*!< LPUART1 Alternate Function mapping */
#define GPIO_AF14_USART1       ((uint8_t)0x0E)  /*!< USART1 Alternate Function mapping */
#define GPIO_AF14_LPTIM1       ((uint8_t)0x0E)  /*!< LPTIM1 Alternate Function mapping */
#define GPIO_AF14_I2C2         ((uint8_t)0x0E)  /*!< I2C2 Alternate Function mapping */
#define GPIO_AF14_TIM3         ((uint8_t)0x0E)  /*!< TIM3 Alternate Function mapping */
#define GPIO_AF14_FDCAN        ((uint8_t)0x0E)  /*!< FDCAN Alternate Function mapping */
#define GPIO_AF14_TIM8         ((uint8_t)0x0E)  /*!< TIM8 Alternate Function mapping */
#define GPIO_AF14_UART1        ((uint8_t)0x0E)  /*!< UART1 Alternate Function mapping */

/**
  * @brief   AF 15 selection
  */
#define GPIO_AF15_EVENT        ((uint8_t)0x0fU) /*!< EVENT Alternate Function mapping */
#define IS_GPIO_AF(AF)         ((AF) <= (uint8_t)0x0f)
/**
  * @}
  */

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
/** @defgroup GPIOEx_Exported_Macros GPIOEx Exported Macros
  * @{
  */

/** @defgroup GPIOEx_Get_Port_Index GPIOEx Get Port Index
  * @{
  */
#define GPIO_GET_INDEX(__GPIOx__)    (((__GPIOx__) == (GPIOA))? 0UL :\
                                      ((__GPIOx__) == (GPIOB))? 1UL :\
                                      ((__GPIOx__) == (GPIOC))? 2UL : 3)

/**
  * @}
  */

/**
  * @}
  */

/* Exported functions --------------------------------------------------------*/
/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __PY32F420_HAL_GPIO_EX_H */

/************************ (C) COPYRIGHT Puya *****END OF FILE******************/
